<?php
	class ExtendedFolderedArticleListGenerator extends FolderedArticleListGenerator {
		
		private $counter = 0; // szamlalja, hogy mennyi cikk van a listaban
		
		function ExtendedFolderedArticleListGenerator($context, $generatorId, $iniParams = null, $skipIniParamsUpdateFromRequest = false) {
			parent::FolderedArticleListGenerator($context, $generatorId, $iniParams, $skipIniParamsUpdateFromRequest);
		}
		
	
		protected function insertExtraArticleTemplateVariables($tpl, $article) {
			$this->counter++;
			
			$langcode =  TextHandler::getCurrentLangcode();
			$articleObj = Article::getArticle($article['id'], SiteHandler::getCurrentSiteId(),$langcode);
			
			if ($articleObj != null) {
				$articleObjImageFilename = $articleObj->logo;					
			} else {
				$articleObjImageFilename = '';
			}
			
			$lead = $articleObj->getLead($langcode);
			
			// ha van kep es lead is, akkor kirakjuk a kepet
			if ($articleObjImageFilename != '' && !empty($lead)) {
				$pattern = "APP_ROOT_URL/";
				if (strpos($articleObjImageFilename, $pattern) === false) {
					// regi
					$articleUrl = ArticleHandler::getArticleUploadUrl(SiteHandler::getCurrentSiteId(), $article['id'], $langcode);
					$articleImageUrl = FileUtil::mergeAndNormalizePaths($articleUrl, $articleObjImageFilename);
				} else {
					// uj
					 $articleObjImageFilename = substr($articleObjImageFilename, strlen($pattern), strlen($articleObjImageFilename));
					 $articleImageUrl = FileUtil::mergeAndNormalizePaths(APP_ROOT_URL, $articleObjImageFilename);
				}
				
				$tpl->setCurrentBlock("newsImage");
				$tpl->setVariable('articleListImage', $articleImageUrl);
				$tpl->parseCurrentBlock();
			}
		}
		
		protected function insertExtraArticleListTemplateVariables($tpl) {
			if ($this->counter < 15) {
				$tpl->replaceBlock("topLink", "", false);
				$tpl->touchBlock("topLink");
			} else {
				$tpl->setCurrentBlock('topLink');
				$tpl->setVariable('topText', TextHandler::getText("back_to_top_text"));
				$tpl->setVariable('topUrl', '#top');
				$tpl->parseCurrentBlock();	
			}
		}
		
	}
	
	
?>